﻿using System;
using System.Collections;
using System.Data;
using System.IO;

public partial class Admin_News_QL_AnhNho : System.Web.UI.Page
{
    Data data = new Data();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            FillComBoBox();
        }
    }

    private void FillComBoBox()
    {
        DataTable table = data.GetTable_By_Name("Slide5anh");
        DropDownList1.DataSource = table;
        DropDownList1.DataTextField = "AnhChayTieuDe";
        DropDownList1.DataValueField = "AnhChayID";
        DropDownList1.DataBind();
    }

    protected void btnChon_Click(object sender, EventArgs e)
    {
        int AnhChayID = int.Parse(DropDownList1.SelectedValue);
        DataTable table = data.GetTable_By_Where("Slide5anh", "where AnhChayID=" + AnhChayID);
        txtTieuDeAnh.Text = table.Rows[0]["AnhChayTieuDe"].ToString();
        txtlinkbandau1.Text = table.Rows[0]["AnhChayLink"].ToString();
        imgHientai1.ImageUrl = "../../Images/Slide5anh/" + table.Rows[0]["AnhChayImage"].ToString();
    }
    protected void btnSave1_Click(object sender, EventArgs e)
    {
        if (imgFuture1.ImageUrl.Equals("")==false)
        {
            data.Edit_LinkSlide5anhUrl(Session["AnhSlide"].ToString(), DropDownList1.SelectedValue, txtTieuDeAnh.Text);
            btnCancel1_Click(sender, e);
        }

    }
    protected void btnCancel1_Click(object sender, EventArgs e)
    {
        Session["AnhSlide"] = null;
        Response.Redirect("Default.aspx");
    }
    protected void btnSaveLink1_Click(object sender, EventArgs e)
    {
        if (txtlinkmoi.Text.Trim().Length != 0)
        {
            data.Edit_LinkSlide5anh(txtlinkmoi.Text,DropDownList1.SelectedValue);
            btnCancel1_Click(sender,e);
        }
    }
    protected void btnUploadThu1_Click(object sender, EventArgs e)
    {
        if (FileUpload1.HasFile)
        {
            FileUpload1.SaveAs(Server.MapPath("../../images/Slide5anh/" + FileUpload1.FileName));
            imgFuture1.ImageUrl = "../../images/Slide5anh/" + FileUpload1.FileName;
            Session["AnhSlide"] = FileUpload1.FileName;
        }
    }
}
